<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:h="http://java.sun.com/jsf/html"
      xmlns:f="http://java.sun.com/jsf/core"
      xmlns:ui="http://java.sun.com/jsf/facelets">

	<ui:composition template="/templates/_template.xhtml">
		<ui:define name="corpo">
			<h:form>
				<fieldset>
					<legend>Dados da nota</legend>
					<h:outputLabel value="CNPJ do cliente" />
					<h:inputText value="#{notaFiscalBean.notaFiscal.cnpj}" />
					
					<h:outputLabel value="Data" />
					<h:inputText value="#{notaFiscalBean.notaFiscal.data.time}">
						<f:convertDateTime pattern="dd/MM/yyyy" timeZone="America/Sao_Paulo"/>
					</h:inputText>
				</fieldset>
				
				<h:commandButton action="#{notaFiscalBean.gravar}" value="Gravar" />
				
				<fieldset>
					<legend>Dados do Item</legend>
					<h:outputLabel value="Produto" />
					<h:selectOneMenu value="#{notaFiscalBean.idProduto}">
						<f:selectItems value="#{produtoBean.produtos}" var="produto" 
							itemValue="#{produto.id}" itemLabel="#{produto.nome}"/>
						
					</h:selectOneMenu>
					
					<h:outputLabel value="Quantidade" />
					<h:inputText value="#{notaFiscalBean.item.quantidade}" />
					
					<h:commandButton action="#{notaFiscalBean.guardaItem}" value="Guardar Item" />
					
				</fieldset>
				
				<h2>Itens da nota fiscal</h2>
				<h:dataTable value="#{notaFiscalBean.notaFiscal.itens}" var="item" styleClass="dados"
					rowClasses="impar,par">
					
					<h:column>
						<f:facet name="header">Produto</f:facet>
						#{item.produto.nome}
					</h:column>
					<h:column>
						<f:facet name="header">Valor Unitario</f:facet>
						<h:outputText value="#{item.valorUnitario}">
							<f:convertNumber type="currency" currencySymbol="R$" locale="pt_BR"/>
						</h:outputText>
					</h:column>
					<h:column>
						<f:facet name="header">Quantidade</f:facet>
						#{item.quantidade}
					</h:column>
					<h:column>
						<f:facet name="header">Total</f:facet>
						<h:outputText value="#{item.total}">
							<f:convertNumber type="currency" currencySymbol="R$" locale="pt_BR"/>
						</h:outputText>
					</h:column>		
				</h:dataTable>
			</h:form>
			
		</ui:define>
	</ui:composition>
</html>